import java.lang.reflect.Array;
import java.util.Arrays;

public class of39 {
    public static void main(String[] args) {
        
    }
    public int majorityElement(int[] nums) {
        Arrays.sort(nums);
        int n=nums.length;
        if(n==1||n==2){
            return nums[n-1];
        }
        int n1=nums[n/2];
        int n2=nums[n/2+1];
        int n3=nums[n/2-1];
        if(n1==n2){
            return n1;
        }
        if(n2==n3){
            return n2;
        }
        else return n1;
    }
}
